package com.example.iconmaker;

import java.nio.IntBuffer;
import java.util.ArrayList;
import java.util.List;

import javax.microedition.khronos.opengles.GL10;

import android.graphics.Bitmap;
import android.opengl.GLUtils;

public class Bar {

	
	public static final float SPACE = 1.0f;
	private List<Icon> icons = new ArrayList<Icon>();
	private int mCount = 0;
	private float mlocation = 0;
	
	
	public void add(float size, int texture) {
		float s = size / 2;
		icons.add(new Icon(-s , s, s , -s, texture));
		mCount++;
	}
	
	public void initTexture(List<Bitmap> bitmaps, GL10 gl) {
		int size = bitmaps.size();

		IntBuffer textureBuffer = IntBuffer.allocate(size);
		gl.glGenTextures(size, textureBuffer);
		int[] textures = textureBuffer.array();
		for (int i = 0; i < size; i++) {
			Bitmap b = bitmaps.get(i);
			gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[i]);
			GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, b, 0);
			gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
			gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
		}

		for (int i = 0; i < size; i++) {
			add(Icon.DEFUALT_SIZE, textures[i]);
		}
	}
	
	public void draw(GL10 gl) {

		// 先平移到转轮圆心并旋转总体角度
		gl.glTranslatef(mlocation, 0.0f, 0.0f);
		int i = 0;
		// 画出每个图标
		do {
			// 只有看得到的才会画出来
			
			icons.get(i).draw(gl);

			gl.glTranslatef(Icon.DEFUALT_SIZE+SPACE, 0.0f, 0.0f);
			i++;
		} while (i < mCount);
	}
}
